package com.exam.xiecheng;

import java.util.Scanner;

/**
 * date:
 * description:
 */
public class Solution001 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int divider = 10;
        int high = x / divider;
        int low = x % divider;
        int ans = 0;
        while(true){
            for (int i = 0; i < 10; i++) {
                if(high == 0 && i == 0){
                    continue;
                }
                ans = high * divider * 10 + i * divider + low;
                if(ans % 7 == 0){
                    System.out.println(ans);
                    return;
                }
            }
            divider *= 10;
            high = x / divider;
            low = x % divider;
        }
    }
}
